package com.teamclub.util.libs;

import com.google.common.io.Files;
import freemarker.template.SimpleDate;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by ilkkzm on 17-9-25.
 */
public class Libs {
    public static File tempDir = Files.createTempDir();
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
    public static Date firstOfDate(Date d) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(d);
        ca.set(11, 0);
        ca.set(12, 0);
        ca.set(13, 0);
        return ca.getTime();
    }
    public static Date endOfDate(Date d) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(d);
        ca.set(11, 23);
        ca.set(12, 59);
        ca.set(13, 59);
        return ca.getTime();
    }

    public static String parseDate(Date d) {
        return sdf.format(d);
    }

    public static String parseyyyyMMdd(Date d) {
        return sdf2.format(d);
    }

    public static File getTempFile(String name) {
        return new File(tempDir, name);
    }

    public static void main(String[] args) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = new Date();
        System.out.println(format.format(now));
        System.out.println(format.format(Libs.firstOfDate(now)));
        System.out.println(format.format(Libs.endOfDate(now)));
    }
}
